import Vue from 'vue'
import Router from 'vue-router'

import Home from "../views/Home";
import aboutUs from "../views/aboutUs";
import contact from "../views/contact";
import Services from "../views/Services/Services";
import ServicesDetails from "../views/Services/ServicesDetails";
import Projects from "../views/Projects/Projects";
import ProjectsDetails from "../views/Projects/ProjectsDetails";
import Information from "../views/Information/Information";
import InformationDetails from "../views/Information/InformationDetails";

// 1、使用Vue.use(插件) 安装 Router
Vue.use(Router);

/**
 * create by Jane
 * 路由配置
 */
const RouterMap = [
    {
        path: '/',
        component: Home,
        // children : []
    },
    {path: '/aboutUs',component: aboutUs},
    {path: '/contact',component: contact},
    {path: '/services', component: Services},
    {path: '/services_details', component:ServicesDetails},
    {path: '/projects', component: Projects},
    {path: '/projects_details', component:ProjectsDetails},
    {path: '/information', component: Information},
    {path: '/information_details', component: InformationDetails},
];

// 2、创建VueRouter对象并导出
const router = new Router({
    // 3、配置路由和组件之间的应用关系
    // mode: 'history',

    routes: RouterMap
});

// 4、全局监听路由变化
router.beforeEach((to, from, next) => {
    // store.dispatch('updateHistoryLength') // 变化时更新路由切换长度
    // console.log('全局监听路由变化',to);
    // window.location.href = to.path;
    next();
})

// 5.导出路由
export default router;
